#ifndef RSIM_TIMER_H
#define RSIM_TIMER_H

/*-------------------------------------------------------------------------- *
* File: Timer.h                                                              *
* Authors: Kishor Bhalerao                                                   *
* Email : kishor8dm@gmail.com                                                *
* Contributors:                                                              *
* Email:                                                                     *
* copyright (c) 2010 Authors.                                                *
*                                                                            *
* This program is free software: you can redistribute it and/or modify it    *
* under the terms of the GNU General Public License as published by the Free *
* Software Foundation, either version 3 of the License, or any later version.*
*                                                                            *
* This program is distributed in the hope that it will be useful, but        *
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
* or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   *
* for more details. (http://www.gnu.org/licenses/)                           *
* -------------------------------------------------------------------------- */

#include <iostream>
#include <ctime>
#include <iomanip>
#include <sys/time.h>
#include <unistd.h>

using namespace std;

namespace RSIM{
        
class Timer{        
        private:
                // clock_t start, finish;
                timeval start, finish;
        public:
                Timer(){
                        gettimeofday(&start,NULL);
                }
                void stop(){
                        // finish = clock();
                        gettimeofday(&finish,NULL);
                }
                void printElapsedTime(int dis=1){
                        double elapsedTime;
                        elapsedTime = static_cast<double>((finish.tv_sec - start.tv_sec) * 1000.0);      // sec to ms
                        elapsedTime += static_cast<double>((finish.tv_usec - start.tv_usec)/1000.0);   // us to ms

                        if(dis){
                                cout<<setprecision(10);                        
                                cout << setw(5) << "Total time: "<< elapsedTime<< " milliseconds"<<endl; 
                        }
                        else{
                                cout<<setprecision(10);
                                cout<<elapsedTime<<endl;                                
                        }
                }
};

}
#endif